<template>
  <div class="app-container">
    <!-- 输入表单 -->
    <el-form ref="form" label-width="80px">
      <el-form-item label="楼层选择">
        <el-select v-model="form_value.floId" placeholder="请选择楼层">
          <el-option
            v-for="item in floors"
            :key="item.floId"
            :label="item.floNum"
            :value="item.floId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="座位状态">
        <el-select
          v-model="form_value.reserveState"
          placeholder="请选择座位状态"
        >
          <el-option
            v-for="item in seatStates"
            :key="item.value"
            :label="item.comment"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="座位数目">
        <el-input-number v-model="form_value.seatCount" :min="0" />
      </el-form-item>
      <el-form-item>
        <el-button
          :disabled="saveBtnDisabled"
          type="primary"
          @click="saveOrUpdate()"
        >
          保存
        </el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import integralGradeAPi from '@/api/core/integral-grade'
export default {
  data() {
    return {
      form_value: {}, // 初始化数据
      floors: {},
      seatStates: [
        {
          value: 1,
          comment: '可预约',
        },
        {
          value: 3,
          comment: '不可预约',
        },
      ],
      value: '',
      value_floor: '',
      saveBtnDisabled: false, // 保存按钮是否禁用，防止表单重复提交
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      integralGradeAPi.listFloors().then((response) => {
        this.floors = response.data.list
      })
    },
    saveOrUpdate() {
      // 禁用保存按钮
      this.saveBtnDisabled = true
      this.saveData()
    },
    // 新增数据
    saveData() {
      console.log(123)
      // debugger
      integralGradeAPi.save(this.form_value).then((response) => {
        this.$message({
          type: 'success',
          message: response.message,
        })
        this.$router.push('/core/integral-grade/list')
      })
    },
  },
}
</script>

<style scoped></style>
